package cn.pigeon.jobs;

import cn.pigeon.health.constant.RedisKeyConstant;
import cn.pigeon.health.utils.QiniuTools;
import org.springframework.beans.factory.annotation.Autowired;
import redis.clients.jedis.JedisPool;

import java.util.Date;
import java.util.Set;

/**
 * 定时删除七牛云垃圾图片
 */
public class ClearImgJob {
    @Autowired
    private JedisPool jedisPool;

    public void clearImg(){

        Set<String> sdiff = jedisPool.getResource().
                                sdiff(RedisKeyConstant.SETMEAL_UPLOAD_PIC, RedisKeyConstant.SETMEAL_UPLOAD_PIC_DB);
        for (String imgName : sdiff) {
            QiniuTools.deleteFile(imgName);
            jedisPool.getResource().srem(RedisKeyConstant.SETMEAL_UPLOAD_PIC,imgName);
            System.out.println("自定义任务，删除了垃圾图片:"+imgName+",时间:"+new Date());
        }
    }
}
